<?php

namespace App\Http\Controllers\CmsApi;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;
use App\Lib\Response;
use App\Http\Controllers\BaseController;
use App\Http\Model\Hint;
use App\Http\Services\EquipAuctionServices;


class InnerEquipAuctionController extends BaseController
{
    protected $equipAuctionServices;

    public function __construct()
    {
        $this->equipAuctionServices = new EquipAuctionServices();

    }

    //用户购买装备扣减金豆处理
    public function buyEquipCostJd(Request $request){
        $user_id = $request->post('user_id',0);
        if(empty($user_id)){
            Response::returnResult(Hint::PARAM_ERROR);
        }
        $info = $request->post('info',[]);
        if(empty($info)){
            Response::returnResult(Hint::PARAM_ERROR);
        }

        $config = config('pay');
        //金豆
        $jd_desc = $config['wallet_change_desc']['jd_equip_acution_decr'];
        //服务
        $data = $this->equipAuctionServices->useJdBuyEquip($user_id,$info['auction_id'],$info['num'],'-'.$info['price'],54,$jd_desc);
        if($data['code'] != Hint::SUCCESS) {
            Response::returnResult($data['code'], $data['data'], $data['msg']);
        }

        Response::returnResult(Hint::SUCCESS);
    }

    //增加金豆
    public function buyEquipAddJd(Request $request){
        $user_id = $request->post('user_id',0);
        if(empty($user_id)){
            Response::returnResult(Hint::PARAM_ERROR);
        }
        $info = $request->post('info',[]);
        if(empty($info)){
            Response::returnResult(Hint::PARAM_ERROR);
        }
        $config = config('pay');
        //金豆描述
        if($info['jd_type'] == 6){
            $jd_desc = $config['wallet_change_desc']['jd_equip_acution_incr'];
        }elseif($info['jd_type'] == 7){
            $jd_desc = $config['wallet_change_desc']['jd_equip_share_incr'];
        }else{
            Response::returnResult(Hint::PARAM_ERROR);
        }
        
        //服务
        $data = $this->equipAuctionServices->useJdBuyEquip($user_id,$info['auction_id'],$info['num'],$info['price'],$info['jd_type'],$jd_desc);

        if($data['code'] != Hint::SUCCESS) {
            Response::returnResult($data['code'], $data['data'], $data['msg']);
        }

        Response::returnResult(Hint::SUCCESS);
    }

    //后台-更改回收用户状态
    public function equipSyschange(Request $request){
        $id = $request->post('id',0); //数据id
        $status = $request->post('status',0);//1=启用 2=禁用
        $res = $this->equipAuctionServices->equipSyschange($id,$status);
        if($res['code'] != Hint::SUCCESS) {
            Response::returnResult($res['code'], $res['data'], $res['msg']);
        }

        Response::returnResult(Hint::SUCCESS);
    }

    //后台-新增回收系统用户
    public function addEquipSyschange(Request $request){
        $user_id = $request->post('user_id',0);//用户id
        $minutes = $request->post('minutes',0);//回收时间间隔
        $res = $this->equipAuctionServices->AddequipSysConfig($user_id,$minutes);
        if($res['code'] != Hint::SUCCESS) {
            Response::returnResult($res['code'], $res['data'], $res['msg']);
        }

        Response::returnResult(Hint::SUCCESS);
    }

    //后台-增加系统用户回收金豆数
    public function addEquipSysJd(Request $request){
        $userId = $request->post('userid',0);
        $dataid = $request->post('dataid',0);
        $price = $request->post('price',0);//增加用户金豆数
        $config = config('pay');
        $jd_desc = $config['wallet_change_desc']['jd_equip_admin_incr'];
        $res = $this->equipAuctionServices->addEquipSysJd($userId,$dataid,8,$price,$jd_desc);
        if($res['code'] != Hint::SUCCESS) {
            Response::returnResult($res['code'], $res['data'], $res['msg']);
        }

        Response::returnResult(Hint::SUCCESS);
    }

    //后台-拍卖行增加修改公聊配置
    public function chageEquipAuctionChatConfig(Request $request){
        $res = $this->equipAuctionServices->chageEquipAuctionChatConfig($request->all());
        if($res['code'] != Hint::SUCCESS) {
            Response::returnResult($res['code'], $res['data'], $res['msg']);
        }
        Response::returnResult(Hint::SUCCESS);
    }
    
    //后台更改-拍卖公聊举报
    public function report(Request $request){
        $res = $this->equipAuctionServices->report($request->all());
        if($res['code'] != Hint::SUCCESS) {
            Response::returnResult($res['code'], $res['data'], $res['msg']);
        }
        Response::returnResult(Hint::SUCCESS);
    }
}